home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 1998-03-30 | 4.0 KB | 124 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- End
- Attribute VB_Name = "clsError"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- Option Explicit
-
- '********************************************************************************************************
- 'Title: clsError
- 'Author: DesignGrid by W. David Ewing, Copyright 1998
- 'Purpose This class allows customizable Global Error trapping. Errors may be displayed, or Logged or both
- ' Set the DisplayErrors Flag to True to display errors to users
- ' Set the LogErrors Flag to True and the LogFileName to the file name which will be
- ' used as the error log in order to log errors to the disk
- '
- 'It is recommended that the this class be declared global for persistence
- '**************************************************************************************
-
- 'Function Where the Error Occurred
- Public FunctionName As String
-
- 'Message is the message to display to the user when
- 'the display function is called, if it is blank, no
- 'message will be displayed
- Public Message As String
-
- 'SQL is the SQL statement being executed at the
- 'time of the error
- Public SQL As String
-
- 'ErrorCode should be set to the error code returned
- 'from the trap in which this class is called from
- Public ErrorCode as Double
-
- 'This flag tells the class whether to display errors to the user or not
- Public DisplayErrors As Boolean
-
- 'if LogErrors is false, no error log is created
- Public LogErrors As Boolean
-
- 'LogFileName is the file which is being used to write an error log
- Public LogFileName As String
-
- 'Success is the flag which is set to false if
- 'the display sub is unsuccessful
- Public Success as Boolean
-
- '********************************************************************************************************
- 'Title: Display
- 'Author: DesignGrid by W. David Ewing, Copyright 1998
- 'Purpose This sub displays a message to the user if the message string is filled
- ' an error log entry if the LogErrors flag is true
- 'Parameters:The Icon and or buttons to put on the msgbox
- 'Return: Nothing
- '********************************************************************************************************
- Public Sub Display(piMsgBoxSuffix As Integer)
-
- If DisplayErrors Then
- If ErrorCode = False Then
- MsgBox Message, piMsgBoxSuffix
- Else
- MsgBox Message & " Error: " & Error(ErrorCode), piMsgBoxSuffix
- End If
- End If
-
- If LogErrors Then
- Success = True
- On Error GoTo DisplayError
- Open LogFileName For Append As 1
- If Not Success Then
- Exit Sub
- End If
- Print #1, "-----------------------------------------------------------"
- If Not Success Then
- Close 1
- Exit Sub
- End If
- Print #1, "Time: " & Format(Now, "mm/dd/yyyy hh:mm:ss")
- If Not Success Then
- Close 1
- Exit Sub
- End If
- If Trim(FunctionName) <> "" Then
- Print #1, "Function: " & FunctionName
- If Not Success Then
- Close 1
- Exit Sub
- End If
- End If
- If Trim(Message) <> "" Then
- Print #1, "Message: " & Message
- If Not Success Then
- Close 1
- Exit Sub
- End If
- End If
- If ErrorCode <> False Then
- Print #1, "Error: " & Error(ErrorCode)
- If Not Success Then
- Close 1
- Exit Sub
- End If
- End If
- If Trim(SQL) <> "" Then
- Print #1, "SQL: " & SQL
- If Not Success Then
- Close 1
- Exit Sub
- End If
- End If
- Close 1
- End If
- Exit Sub
-
- DisplayError:
- Success = False
- Resume Next
-
- End Sub
-